package com.gjj.abox;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import com.gjj.abox.database.BoxDB;

import butterknife.ButterKnife;

public class BaseActivity extends Activity {
    protected InputMethodManager manager;
    protected BoxDB boxDb = null;
    protected Toast toast;
    protected final static String PREFERENCE_NAME = "source";
    protected  SharedPreferences sharedpreferences = null;
    protected SharedPreferences.Editor edit = null;

    //merge branch
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initialize();
    }
    private void initialize(){
        manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        boxDb = new BoxDB(getApplicationContext());
        sharedpreferences = getSharedPreferences(
                PREFERENCE_NAME, Activity.MODE_PRIVATE);
        edit = sharedpreferences.edit();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (getCurrentFocus() != null
                    && getCurrentFocus().getWindowToken() != null) {
                manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
        return super.onTouchEvent(event);
    }


    public void showTips(Context context,String string){
        if(toast != null){
            toast.cancel();
            Toast.makeText(context,string,Toast.LENGTH_LONG).show();
        }
    }
}
